﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using BSU.GraduateWork.Data.Model;
using BSU.GraduateWork.Data.Repositories.Interfaces;
using BSU.Math.Geometry;

namespace BSU.GraduateWork.Data.Repositories
{
    public class Point2DRepository : BaseRepository<SolutionPoint2D, int>, IPoint2DRepository
    {
        public void SaveAll(List<SolutionPoint2D> points)
        {
            var context = GetNewContext();
            var table = context.GetTable<SolutionPoint2D>();
            foreach (var point in points)
            {
                table.InsertOnSubmit(point);    
            }
            context.SubmitChanges();
        }

        public IList<Point3D> List(int solutioinId)
        {
            var context = GetNewContext();
            var points = context.Points2D;

            return
                points
                    .Where(x => x.SolutionId == solutioinId)
                    .Select(x => new Point3D(x.X, x.Y, x.U, x.IsBoundary))
                    .ToList();
        }
    }
}